<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_City_setting_entity{
	var $current_dbprefix = "";
	var $id = 0;
	var $city ="";
	var $province_id ="";
	var $country_id ="";
	var $discount ="";
		
	function __construct() {
		$ci= & get_instance();
		$this->current_dbprefix = $ci->db->dbprefix;
		$ci->db->set_dbprefix('default_');
	}
	function __destruct() {
		$ci= & get_instance();
		$ci->db->set_dbprefix($this->current_dbprefix);
	}	
	
	function setId($input){
		$this->id=$input;
	}
	function setCity($input){
		$this->city = $input;
	}
	function setProvinceId($input){
		$this->province_id = $input;
	}
	function setCountryId($input){
		$this->country_id = $input;
	}
	function setDiscount($input){
		$this->discount = $input;
	}
	function getId(){
		return $this->id;
	}
	function getCity(){
		return $this->city;
	}
	function getProvinceId(){
		return $this->province_id;
	}
	function getCountryId(){
		return $this->country_id;
	}
	function getDiscount(){
		return $this->discount;
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		if($cmd == 'id'){
			$result = $ci->db->where('id',$input)->get(TBL_CITY_SETTING)->result();
		}else if($cmd == 'province_id'){
			$result = $ci->db->where('province_id',$input)->get(TBL_CITY_SETTING)->result();
		}else if($cmd == 'country_id'){
			$result = $ci->db->where('country_id',$input)->get(TBL_CITY_SETTING)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->city = $result[0]->city;
			$this->province_id = $result[0]->province_id;
			$this->country_id = $result[0]->country_id;
			$this->discount = $result[0]->discount;
			return $this;
		}
		return false;
	}
	function getLanguageList(){
		$ci=& get_instance();
		return $ci->db->get(TBL_CITY_SETTING)->result();
	}
	function save(){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->set('city',$this->getCity());
		$ci->db->set('province_id',$this->getProvinceId());
		$ci->db->set('country_id',$this->getCountryId());
		$ci->db->set('discount',$this->getDiscount());
		$ci->db->insert(TBL_CITY_SETTING);
		return $ci->db->insert_id();
	}
	function update(){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->set('city',$this->getCity());
		$ci->db->set('province_id',$this->getProvinceId());
		$ci->db->set('country_id',$this->getCountryId());
		$ci->db->set('discount',$this->getDiscount());
		return $ci->db->where('id', $this->id)->update(TBL_CITY_SETTING);
	}
	function delete($id){
		$ci=& get_instance();
		$ci->db->set_dbprefix('default_');
		
		$ci->db->where('id',$id);
		$ci->db->delete(TBL_CITY_SETTING);
	}
}